// Google Analytics tracking events.
$(function () {
    /// Query - Get in touch button click tracking BEGIN
    $('a.getintouch').live('click', function () {
        _gaq.push(['_trackEvent', 'Get in Touch', 'Form click', 'Homepage Contact form click']);
    });
    /// Query - Get in touch button click tracking END

    /// Footer links tracking BEGIN
    var page = $('body').attr('data-title');

    $('footer .links #hlEAME').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Footer link - Maps API for Business', 'outbound click', 'API text link click']);
    });
    $('footer .links #hlPrivacy').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Footer link - Google Privacy Policy', 'outbound click', 'Privacy policy link click']);
    });
    $('footer .links #hlGuidelines').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Footer link - Acceptable Use Policy', 'outbound click', 'Acceptable Use policy link click']);
    });
    $('footer .logo').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Footer link - Maps API for Business', 'outbound click', 'API image link click']);
    });
    $('footer .addthis_button_email').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Share site - email', 'Share Site', 'Share to Email']);
    });
    $('footer .addthis_button_linkedin').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + 't) Share site - linkedIn', 'Share Site', 'Share to Linked In']);
    });
    $('footer .addthis_button_twitter').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Share site - twitter', 'Share Site', 'Share to Twitter']);
    });
    $('footer .addthis_button_facebook').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Share site - facebook', 'Share Site', 'Share to Facebook']);
    });
    $('footer .plusone').live('click', function () {
        _gaq.push(['_trackEvent', '(Desktop ' + page + ') Share site - Google Plus', 'Share Site', 'Share to Google Plus']);
    });
    /// Footer links tracking END

    /// Events Pages BEGIN
    if ($('.events').length > 0) {
        var city = $('.events').attr('data-city');

        $('.events .main-content .intro .button').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Register Now', 'click', 'Load registration form']);
        });
        $('.events footer .links #hlEAME').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Footer link - Maps API for Business', 'outbound click', 'API text link click']);
        });
        $('.events footer .links #hlPrivacy').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Footer link - Google Privacy Policy', 'outbound click', 'Privacy policy link click']);
        });
        $('.events footer .links #hlGuidelines').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Footer link - Acceptable Use Policy', 'outbound click', 'Acceptable Use policy link click']);
        });
        $('.events footer .links .logo').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Footer link - Maps API for Business', 'outbound click', 'API image link click']);
        });
        $('.events footer .addthis_button_email').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Share site - email', 'Share Site', 'Share to Email']);
        });
        $('.events footer .addthis_button_linkedin').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Share site - linkedIn', 'Share Site', 'Share to Linked In']);
        });
        $('.events footer .addthis_button_twitter').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Share site - twitter', 'Share Site', 'Share to Twitter']);
        });
        $('.events footer .addthis_button_facebook').live('click', function () {
            _gaq.push(['_trackEvent', '(' + city + ' Event) Share site - facebook', 'Share Site', 'Share to Facebook']);
        });
    }
    /// Events Pages END
});

/// Tracks the hovers and clicks of the industry tiles.
function trackTile(eventType, sector) {
    if (eventType == 'mouseover') {
        _gaq.push(['_trackEvent', getIndustry(sector) + ' hoverstate', 'mouse-hover']);
    }
    else if (eventType == 'click') {
        _gaq.push(['_trackEvent', getIndustry(sector) + ' click', 'click']);
    }
}


function getIndustry(sector) {
    switch (sector) {
        case "telco":
            return "Telco";
        case "utilities":
            return "Utilities";
        case "resource":
            return "Natural Resources";
        case "government":
            return "Government";
        case "financial":
            return "Banking";
        case "telcoinfo":
            return "Telco";
        case "utilitiesinfo":
            return "Utilities";
        case "resourceinfo":
            return "Natural Resources";
        case "governmentinfo":
            return "Government";
        case "financialinfo":
            return "Banking";
        default:
            return "";
    }
}

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.search);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}
